package com.hellenic.servlets;

import java.io.IOException;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.hibernate.SessionFactory;

import com.hellenic.beans.ProprieteBean;
import com.hellenic.mod.ProprieteMod;

@SuppressWarnings( "serial" )
public class Accueil extends HttpServlet {
    public static final String VUE               = "/WEB-INF/accueil.jsp";
    public static final int    ATTR_NB_PROPRIETE = 4;
    public static final String ATTR_DAO_FACTORY  = "sessionF";

    private ProprieteMod          proprieteM;

    public void init() throws ServletException {
        // Récupération de l'objet SessionFactory
        SessionFactory sf = (SessionFactory) getServletContext().getAttribute( "ATTR_DAO_FACTORY" );
        // intanciation de la classe metier
        proprieteM = new ProprieteMod( sf );
        System.out.println( "Message : Initialisation servlet connexion" );
    }

    public void doGet( HttpServletRequest request, HttpServletResponse response ) throws ServletException, IOException {
        // recuperation de n bien
        ArrayList<ProprieteBean> list = proprieteM.listingPropriete( ATTR_NB_PROPRIETE );
        // stockage des biens dans l'obj request
        request.setAttribute( "lesProprietes", list );
        // passage a la page jsp
        this.getServletContext().getRequestDispatcher( VUE ).forward( request, response );
    }
}
